enum Color
{
	Hex(str:String);
	RGB(x:Int,y:Int,z:Int);
	cFloat(f:Float);
}

class ColorConverter
{
	public static function toFloat (c:Color)
	{
		return switch (c)
		{
			case Hex(str) : convertStringHexToFloat(str);
			case RGB(r,g,b): (r << 16) | (g << 8) | b; // returns a Float or Int?
			case cFloat(f) : f;
		}
	}

	public static function toInt (c:Color) : Int
	{
		return Std.int(toFloat(c));
	}

	public static function toString (c:Color) : String
	{
		return switch (c)
		{
			case Hex(str) : str;
			case RGB(r,g,b): Std.string((r << 16) | (g << 8) | b);
			case cFloat(f) : Std.string(f);	
		}	
	}

	public static function convertStringHexToFloat(s:String) : Float {
		if( s.substr(0,2) == '0x' )
			return Std.parseFloat(s);
	
		if( s.substr(0,1) == '#' )
		{
			if (s.length == 7) {
				return Std.parseFloat( '0x' + s.substr(1,s.length) );
			}else if (s.length == 4) {
				var st : String = '';
				for ( i in 1...4 )
				{
					var t = s.substr(i,i+1);
					st += t + t;
				}
				return Std.parseFloat( '0x' + st );
			}
		}
		return 0;
	}
}
